package com.travel.goods.dao;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.travel.goods.entity.Goods;
import java.lang.Long;

/**
 * @classDesc: 功能描述:()
 * @author:<a href="leeue@foxmail.com">李月</a>
 * @Version:v1.0
 * @createTime:2019年3月19日 下午4:41:07
 */
@Repository
public interface GoodsDao extends JpaRepository<Goods, Long> {

	// 根据城市来查找热门产品

	@Query(value = "SELECT goods FROM Goods goods where goods.goodsCity =:goodCity ORDER BY goods.goodWeight DESC")
	List<Goods> findByGoodsCity(String goodCity);

	// 根据商品名称来查找 模糊查找
	@Query(value = "SELECT goods FROM Goods goods where goods.goodsName LIKE CONCAT('%',:goodsName,'%') ORDER BY goods.goodWeight DESC")
	List<Goods> findByGoodsName(@Param("goodsName") String goodsName);

	/**
	 * 根据id查找
	 */

	Optional<Goods> findById(Long id);

}
